package com.xinlu.common.game.action;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;

import com.xinlu.common.game.bo.ConstantLstBo;
import com.xinlu.common.game.bo.TzjlBo;
import com.xinlu.common.game.form.FaglForm;
import com.xinlu.derek.common.BaseAction;
import com.xinlu.derek.common.BaseForm;
import com.xinlu.persistence.Users;
import com.xinlu.user.bo.UsersBo;
import com.xinlu.util.tool.DateUtil;

public class FaglAction extends BaseAction {

	private TzjlBo tzjlBo;
	private UsersBo usersBo;

	public void setUsersBo(UsersBo usersBo) {
		this.usersBo = usersBo;
	}

	FaglForm fr = new FaglForm();

	public void setTzjlBo(TzjlBo tzjlBo) {
		this.tzjlBo = tzjlBo;
	}

	public void setFr(FaglForm fr) {
		this.fr = fr;
	}

	@Override
	public String doExecute() throws Exception {
		return null;
	}

	@Override
	public void formInit() {
	}

	@Override
	public BaseForm getModel() {
		return fr;
	}

	/**
	 * 加载页面
	 * 
	 * @return
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 */
	public String loadPage() throws IllegalAccessException, InvocationTargetException {

		Users crtUser = null;
		if (ConstantLstBo.isNullOrEmpty(fr.getCrtYhm())) {
			crtUser = (Users) getSession().getAttribute("userinfo");
		} else {
			crtUser = usersBo.loadUser(fr.getCrtYhm());
		}

		fr.setCaiZhongs(ConstantLstBo.getCaiZhongs());
		Date date = new Date();
		String bgnDate = DateUtil.getFormatDate(DateUtil.YYYY_MM_DD, date);
		String endDate = DateUtil.getFormatDate(DateUtil.YYYY_MM_DD, DateUtils.add(date, 5, 1));
		fr.setBgnDate(bgnDate+ConstantLstBo.getBgnHMS(bgnDate));
		fr.setEndDate(endDate+ConstantLstBo.getBgnHMS(endDate));
		fr.setPageObject(tzjlBo.loadFagls(crtUser, "--全部--", fr.getBgnDate(),fr.getEndDate(), null, null, null, null, fr.getPn()));
		return "fagl";
	}

	/**
	 * 加载方案管理
	 * 
	 * @return
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 */
	public String loadFagl() throws IllegalAccessException, InvocationTargetException {

		Users crtUser = null;
		if (ConstantLstBo.isNullOrEmpty(fr.getCrtYhm())) {
			crtUser = (Users) getSession().getAttribute("userinfo");
		} else {
			crtUser = usersBo.loadUser(fr.getCrtYhm());
		}

		fr.setCaiZhongs(ConstantLstBo.getCaiZhongs());
		fr.setPageObject(tzjlBo.loadFagls(crtUser, fr.getCaiZhong(), fr.getBgnDate(), fr.getEndDate(), fr.getDzh(), fr.getQh(), fr.getXjyhm(), fr
				.getZhm(), fr.getPn()));
		return "fagl";
	}
}